import { put } from "redux-saga/effects";

const successResponseCodes = [
  "200",
  "201",
  "202",
  "203",
  "204",
  "205",
  "206",
  "207",
  "208",
  "1000",
];

function* interceptResponse(response, throwError = true) {
  console.log("request response====>", response, throwError);
  if (!successResponseCodes.includes(String(response.status))) {
    if (throwError) {
      throw response;
    } else {
      return false;
    }
  }
  return true;
}

export default interceptResponse;
